<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <link rel="stylesheet" href="./lib/time-rule.css">
  <style>
    html,
    body {
      height: 100%;
      margin: 0;
      padding: 0;
      background-color: #999;
    }
    .box {
      /* width: 700px; */
    }
  </style>
</head>
<body>
  <div>时间轴插件</div>
  <div class="box"><div id="time-rule"></div></div>
  <button onclick="init()">初始化</button>
  <button onclick="gotoTime23()">跳转到指定23点</button>
  <button onclick="gotoTime02()">跳转到指定02点</button>
  <button onclick="pause()">暂停</button>
  <button onclick="play()">播放</button>
  <script src="./lib/jquery.js"></script>
  <script src="./lib/time-rule.js"></script>
  <script>
    var recordData = [
        {
          "startTime": "2021-04-14 05:56:58",
          "endTime": "2021-04-14 10:13:51"
        },
        {
          "startTime": "2021-04-14 13:13:51",
          "endTime": "2021-04-14 14:30:44"
        },
        {
          "startTime": "2021-04-14 14:30:44",
          "endTime": "2021-04-14 15:47:37"
        },
        {
          "startTime": "2021-04-14 15:47:37",
          "endTime": "2021-04-14 17:04:30"
        },
        {
          "startTime": "2021-04-14 15:47:37",
          "endTime": "2021-04-14 17:04:30"
        },
        {
          "startTime": "2021-04-14 17:04:30",
          "endTime": "2021-04-14 18:21:23"
        },
        {
          "startTime": "2021-04-14 18:21:23",
          "endTime": "2021-04-14 19:38:16"
        },
        {
          "startTime": "2021-04-14 19:38:16",
          "endTime": "2021-04-14 20:55:09"
        },
        {
          "startTime": "2021-04-14 20:55:09",
          "endTime": "2021-04-14 22:12:02"
        },
        {
          "startTime": "2021-04-14 22:12:02",
          "endTime": "2021-04-14 23:28:55"
        },
        {
          "startTime": "2021-04-14 23:28:55",
          "endTime": "2021-04-14 24:00:00"
        }
      ]
    
    function init () {
      Rule.stop()
      Rule.init({ el: '#time-rule', recordData: recordData, space: 60, isShowToolBar: true }, beforeInit, afterInit)
      Rule.afterDrag({
        success: function (startTime, endTime) {
          console.log(startTime, endTime);
          if(startTime.split(' ')[0] === endTime.split(' ')[0]) {
            Rule.move()
          }
        },
        error: function () {
          alert('afterDrag--当前无视频')
        }
      })
    }
    function beforeInit(config) {
      // if (config.space === 60) {
      //   $('.box').css('padding-left', 60)
      // } else {
      //   $('.box').css('top', 0)
      // }
    }
    function afterInit(config) {
      console.log(config);
    }
    function gotoTime23() {
      var res = Rule.gotoTime({ hour: '23', minute: '10', second: '00' })
      if(res.isError) {
        alert(res.message)
      } else {
        console.log('播放');
        Rule.move()
      }
    }
    function gotoTime02() {
        var res = Rule.gotoTime({ hour: '02', minute: '00', second: '00' })
        if (res.isError) {
          alert(res.message)
        } else {
          console.log('播放');
          Rule.move()
        }
      }
    function play() {
      console.log('播放');
      var res = Rule.getPointInfo()
      console.log(res);
      Rule.move()
    }
    function pause() {
      console.log('暂停播放');
      Rule.stop()
    }
    init()
  </script>
</body>
</html>